package algo_annotations.heuristique;


public class Evolution {

	EvolutiveValue poids;
	EvolutiveValue param;

	public Evolution() {
		poids = null;
		param = null;
	}

	public void setProfilPoids(double valInit, double valPic, double valFin, int t0, int t1, int t2, int t3) {
		poids = new EvolutiveValue(valInit, valPic, valFin, t0, t1, t2, t3);
	}
	public void setProfilPoids_cte(double val) {
		poids = new EvolutiveValue(val, val, val, 0, 0, 0, 0);
	}
	public void setProfilPoids_decroissSimple(double valInit, double valFin, int duree) {
		poids = new EvolutiveValue(valInit, valInit, valFin, 0, 0, 0, duree);
	}
	public void setProfilPoids_croissDifferee(double valFin, int iterStart, int iterPic) {
		poids = new EvolutiveValue(0, valFin, valFin, iterStart, iterPic, iterPic, iterPic);
	}

	public void setProfilParam(double valInit, double valPic, double valFin, int t0, int t1, int t2, int t3) {
		param = new EvolutiveValue(valInit, valPic, valFin, t0, t1, t2, t3);
	}
	public void setProfilParam_cte(double val) {
		param = new EvolutiveValue(val, val, val, 0, 0, 0, 0);
	}
	public void setProfilParam_decroissSimple(double valInit, double valFin, int duree) {
		param = new EvolutiveValue(valInit, valInit, valFin, 0, 0, 0, duree);
	}
	public void setProfilParam_croissDifferee(double valFin, int iterStart, int iterPic) {
		param = new EvolutiveValue(0, valFin, valFin, iterStart, iterPic, iterPic, iterPic);
	}


	public double getPoidsForThisIter(int numIter) {return poids.getValueForIter(numIter);}
	public double getParamForThisIter(int numIter) {return param.getValueForIter(numIter);}
	

	private class EvolutiveValue {
		private double valInit, valPic, valFin;
		private int t0, t1, t2, t3;


		public EvolutiveValue(double valInit, double valPic, double valFin, int t0, int t1, int t2, int t3) {
			assert(t0<=t1 && t1<=t2 && t2<=t3);
			this.valInit=valInit;
			this.valPic=valPic;
			this.valFin=valFin;
			this.t0=t0;
			this.t1=t1;
			this.t2=t2;
			this.t3=t3;
		}

		public double getValueForIter (int numIter) {
			assert (numIter>=1);

			if (numIter<=t0)
				return valInit;

			if (numIter<=t1) {
				if (t0==t1)
					return valPic;
				else
					return ((double)numIter-t0)/((double)t1-t0)*(valPic-valInit) + valInit;
			}

			if (numIter<=t2)
				return valPic;

			if (numIter<=t3) {
				if (t2==t3)
					return valFin;
				else
					return ((double)numIter-t2)/((double)t3-t2)*(valFin-valPic) + valPic;
			}
			return valFin;
		}

	}
}
